# app/core/handlers/response.py
from typing import Any, Generic, TypeVar

from fastapi import status
from pydantic import BaseModel, Field

T = TypeVar("T")


class BaseResponse(BaseModel, Generic[T]):
    """基础响应模型"""

    success: bool = Field(True, description="是否成功")
    data: T | None = Field(None, description="响应数据")
    message: str | None = Field(
        "",
        description="响应消息",
    )
    code: int | None = Field(200, description="响应码")


class SuccessResponse(BaseResponse):
    """成功响应"""

    def __init__(
        self,
        data: Any = None,
        message: str = "操作成功",
        code: int = status.HTTP_200_OK,
        **kwargs,
    ):
        super().__init__(success=True, data=data, message=message, code=code, **kwargs)


class FailResponse(BaseResponse):
    """失败响应"""

    def __init__(
        self,
        message: str = "操作失败",
        code: int = status.HTTP_500_INTERNAL_SERVER_ERROR,
        data: Any = None,
        **kwargs,
    ):
        super().__init__(success=False, data=data, message=message, code=code, **kwargs)
